//
//  BaseViewController.m
//  xpkc
//
//  Created by TopSageOSX on 14/12/20.
//  Copyright (c) 2014年 wanmeizty. All rights reserved.
//

#import "BaseViewController.h"
#import "UserMessage.h"
@interface BaseViewController ()

@end

@implementation BaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        [self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                [UIColor colorWithRed:255/255.0f green:159/255.f blue:0/255.f alpha:1], NSForegroundColorAttributeName,
                                                nil] forState:UIControlStateSelected];
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self creatNavItem];
    if (IsIOS7) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    self.view.backgroundColor = [UIColor whiteColor];
}

#pragma mark -
#pragma mark == creatNav ==
/**
 *  创建导航按钮
 */
- (void)creatNavItem{
    UIImage *backimg = [UIImage imageNamed:@"back1"];
    if (IsIOS7) {
        backimg = [backimg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    UIBarButtonItem *backitem = [[UIBarButtonItem alloc]initWithImage:backimg style:UIBarButtonItemStyleBordered target:self action:@selector(backToLastView)];
    self.navigationItem.leftBarButtonItem = backitem;
    
    UIImage *shopcartimg = [UIImage imageNamed:@"shopcart"];
    if (IsIOS7) {
        shopcartimg = [shopcartimg imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    UIBarButtonItem *shopcart = [[UIBarButtonItem alloc]initWithImage:shopcartimg style:UIBarButtonItemStyleBordered target:self action:@selector(gotoShopCart)];
    self.navigationItem.rightBarButtonItem = shopcart;
}
/**
 *  返回上一页
 */
- (void)backToLastView{
    [self.navigationController popViewControllerAnimated:YES];
}
/**
 *  前往购物车
 *  均使用push
 */
- (void)gotoShopCart{
    
    
//    logdebug(@"购物车");
    if (![UserMessage sharedUserMessage].isLogin) {
        [self showAlertWithMessage:@"请先登陆"];
    }else{
        CourseCenterCartViewController *CCCVC = [[CourseCenterCartViewController alloc]init];
        CCCVC.hidesBottomBarWhenPushed = YES;
        if (IsIOS7) {
            if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
                self.navigationController.interactivePopGestureRecognizer.delegate = nil;
            }
        }
        [self.navigationController setNavigationBarHidden:NO animated:NO];
        [self.navigationController pushViewController:CCCVC animated:YES];
    }

//
//    CourseCenterCartViewController *CCCVC = [[CourseCenterCartViewController alloc]init];
//    CCCVC.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:CCCVC animated:YES];
    
    
    
}
- (void)showAlertWithMessage:(NSString *)message {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
    [alertView show];
}

#pragma mark -
#pragma mark == other ==
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
